<template>
	<view class="pb-30 index-box">
		<view class="location">
			<view class="location-left">
				<u-icon name="map" size="38" color="#000" /><text class="ml-10">物管家演示项目</text>
			</view>
			<view>
				<u-icon name="arrow-down" />
			</view>
		</view>
		<view class="attention" v-if="closeBut">
			<view class="attention-left">
				<u-avatar :src="src" mode="square" size="55" class="avatar"></u-avatar>
				<text class="ml-10">欢迎访问物业，点击关注我们哦~</text>
			</view>
			<view>
				<u-button type="error" size="mini" class="mr-20">点击关注</u-button>
				<u-icon name="close" @click="closeBut=false" />
			</view>
		</view>
		<view class="section-body">
			<view class="swiper-box">
				<u-swiper :list="list" height="300rpx"></u-swiper>
			</view>
			<view class="grid-box">
				<view v-for="(item,index) in gridList" :key="index" class="grid-item" @click="openAppointment(index)">
					<u-icon :name="item.icon" :size="66"></u-icon>
					<view class="grid-text mt-10">{{item.text}}</view>
				</view>
			</view>
			<view class="content">
				<view class="row-gs">
					<view class="title">
						<view>物业公告</view>
						<view @click="noticeBar(currentItem)">
							<u-notice-bar mode="vertical" :volume-icon="false" :font-size="24" :duration="3500" bg-color="#fff" color="#999" :list="titleCharacters"></u-notice-bar>
						</view>
						<view @click="openServe(0)">更多</view>
					</view>
				</view>
				<view class="c-rwo row-fw ">
					<view class="title">
						<view>社区服务</view>
						<view>便民快捷</view>
						<view  @click="openSw">更多</view>
					</view>
					<view class="mu-grid">
						<view v-for="(item,index) in communityList" :key="index"
							:style="{background:`url(${item.bgImg}) 0% 0% / cover no-repeat`}" @click="openServe(index)">
							<view class="item-left">
								<text class="mu-title">{{item.title}}</text>
								<text class="mu-text" :style="{color:item.color}">{{item.text}}</text>
							</view>
						</view>
					</view>
				</view>
				<view class="c-rwo row-dt">
					<view class="title">
						<view>最新动态</view>
						<view>社区也有好新闻</view>
						<view>更多</view>
					</view>
					<view class="nrong">
						<view class="matter">
							<u-divider color="$-color-muted" class="divider">暂未发布动态</u-divider>
						</view>
					</view>
				</view>
				<view class="c-rwo row-zx">
					<view class="title">
						<view>邻里中心</view>
						<view>畅谈邻里</view>
						<view>更多</view>
					</view>
					<view class="nrong">
						<view class="matter" v-if="false">
							<u-divider color="$-color-muted" class="divider">暂未发布动态</u-divider>
						</view>
						<view class="column mb-30 pb-30" v-for="(item,index) in llCenter" :key="index">
							<view class="column-left">
								<u-button type="primary" size="mini" :custom-style="customStyle"
									v-for="(sonItme,sonIndex) in item.butonText" :key="sonIndex">{{sonItme}}</u-button>
								<view class="mt-20 mb-20 pltitle">{{item.title}}</view>
								<view class="info">
									<view class="info-left">
										<u-avatar :src="src" mode="circle" size="40" class="avatar"></u-avatar>
										<text class="ml-10">{{item.name}}</text>
									</view>
									<view class="info-right">
										<u-icon name="eye" size="25" color="$-color-muted" />
										<text class="ml-5 mr-20 ">{{item.num}}</text>
										<text class="hit">{{item.hour}}</text>
									</view>
								</view>
							</view>
							<view class="column-right">
								<u-image width="100%" height="200rpx" border-radius="10" :src="item.infoImgUrl"  mode="widthFix"></u-image>
							</view>
						</view>
					</view>
				</view>
				<view class="c-rwo row-hd">
					<view class="title">
						<view>社区活动</view>
						<view>社区活动动态学握</view>
						<view>更多</view>
					</view>
					<view class="nrong">
						<view class="matter">
							<u-divider color="$-color-muted" class="divider">暂未发布动态</u-divider>
						</view>
						<view class="mt-50">
							<u-gap height="5" bg-color="#bbb"></u-gap>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="relevance">
			<view class="fs-24 mb-10 mt-5">小可爱关联的公众号</view>
			<view class="cell">
				<view>
					<u-avatar :src="src" mode="square" size="70" class="avatar"></u-avatar>
					<view class="tb ml-20">
						<text style="color: black;">腾湖物管家</text>
						<text class="fs-20">欢迎来到小可爱的公众号，点击关注有礼</text>
					</view>
				</view>
				<u-button size="mini" class="mr-26" plain :custom-style="attentionStyle">关注</u-button>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getLocalImg
	} from '@/utils/localFileUtil.js';
	
	import { latestNewsPage } from '@/api/base/latestNewsApi.js';
	
	export default {
		
		data() {
			const src ='https://picsum.photos/200'
				
			const infoImgUrl = "https://picsum.photos/200"
			return {
				cardList: [],
				currentIndex: 0,
				currentItem: null,
				timer: null,
				titleCharacters: [],
				attentionStyle: {
					padding: '0 30rpx',
				},
				closeBut: true,
				src,
				llCenter: [{
						title: '儿童轮滑鞋，闲置低价处理！',
						head: '',
						name: '佳冰',
						num: 4,
						hour: '10-27',
						butonText: ['闲置'],
						infoImgUrl
					},
					{
						title: '闲置冰箱，满足3人家庭使用，底价出手',
						head: '',
						name: 'yjb',
						num: 21,
						hour: '10-27',
						butonText: ['二手好物'],
						infoImgUrl
					}
				],
				customStyle: {
					width: '100rpx',
					height: '35rpx',
					fontSize: '20rpx',
					backgroundColor: '#3399ff',
					borderRadius: '5rpx',
					padding: '0 10rpx'
				},
				communityList: [{
						title: "小区公告",
						text: "通晓社区新闻",
						icon: "phone",
						bgImg: getLocalImg('wy_23.png'),
						color: "#7ecaf7"
					},
					{
						title: "服务团队",
						text: "物业团队专属服务",
						icon: "phone",
						bgImg: getLocalImg('wy_24.png'),
						color: "#ee85f8"
					},
					{
						title: "投诉建议",
						text: "社区事务一键反应",
						icon: "phone",
						bgImg: getLocalImg('wy_25.png'),
						color: "#f5a32f"
					},
					{
						title: "我的车辆",
						text: "车位车辆快速通行",
						icon: "phone",
						bgImg: getLocalImg('wy_26.png'),
						color: "#937afc"
					}
				],
				gridList: [{
						text: "访客预约",
						icon: getLocalImg('wy_30.jpg')
					},
					{
						text: "报事报修",
						icon: getLocalImg('wy_31.jpg')
					},
					{
						text: "缴费中心",
						icon: getLocalImg('wy_32.jpg')
					},
					{
						text: "邻里中心",
						icon: getLocalImg('wy_33.jpg')
					}
				],
				list: [{
						image: getLocalImg('banner1.png')
					},
					{
						image: getLocalImg('banner2.png')
					}
				],
			}
		},
		mounted() {
				this.loadData()
			},
		methods: {
				async loadData() {
						try {
							const response = await latestNewsPage()
							this.cardList = response.records
							// 开始展示第一条公告
							this.showNextNotice()
						} catch (error) {
							console.error('error', error)
						}
					},
					showNextNotice() {
					    if (this.currentIndex === this.cardList.length) {
					        this.currentIndex = 0 // 重置为第一个公告
					    }
					    this.currentItem = this.cardList[this.currentIndex]
					    this.titleCharacters = [this.currentItem.title] // 包装标题为单个元素的数组
					    this.currentIndex++
					    this.timer = setTimeout(() => {
					        this.showNextNotice()
					    }, 2000)
					},
			openSw(){
				uni.switchTab({
					url:"/masterPack/index/serve"
				})
			},
				noticeBar(currentItem) {
						this.$u.route('/subPack/noticeDetails', {
							title: currentItem.title,
							id: currentItem.id
						})
					},
			openServe(index) {
				switch (index) {
					case 0:
						uni.navigateTo({
							url: "/subPack/announcement"
						})
						break;
					case 1:
						uni.navigateTo({
							url: "/subPack/serviceTeam"
						})
						break;
					case 2:
						uni.navigateTo({
							url: "/subPack/complaint"
						})
						break;
					case 3:
						uni.navigateTo({
							url: "/subPack/myCar"
						})
						break;
					default:
						break;
				}
			},
			openAppointment(index) {
				switch (index) {
					case 0:
						uni.navigateTo({
							url: "/subPack/appointment"
						})
						break;
					case 1:
						uni.navigateTo({
							url: "/subPack/repairs"
						})
						break;
					case 2:
						uni.navigateTo({
							url: "/subPack/payment"
						})
						break;
					default:
						break;
				}
			}
		},
		beforeDestroy() {
				// 清除定时器
				clearTimeout(this.timer);
			},
	}
</script>

<style lang="scss" scoped>
	.location {
		height: 80rpx;
		line-height: 80rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 0 20rpx;

		.location-left {
			display: flex;
			align-items: center;
		}
	}

	.attention {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 20rpx;
		background-color: $-color-white;

		.attention-left {
			display: flex;
			align-items: center;


			/deep/.u-avatar {
				vertical-align: middle;
			}
		}
	}

	.swiper-box {
		padding: 20rpx 0;
		margin: 20rpx 0;
	}

	.grid-box {
		display: flex;
		justify-content: space-between;

		.grid-item {
			flex: 1;
			text-align: center;
			background-color: $-color-white;
			padding: 30rpx 10rpx;
			border-radius: 5%;
		}

		.grid-item:nth-child(2) {
			margin: 0 20rpx;
		}

		.grid-item:nth-child(3) {
			margin: 0 20rpx 0 0;
		}
	}

	.section-body {
		padding: 0 20rpx;
	}

	.content {
		margin-top: 20rpx;

		.c-rwo {
			background-color: $-color-white;
			margin-bottom: 20rpx;
			border-radius: 5rpx;
			padding-bottom: 30rpx;

			.nrong {
				padding: 0 20rpx;
			}


		}

		.title {
			display: flex;
			background-color: $-color-white;
			padding: 20rpx 20rpx;
			align-items: center;
			margin-bottom: 20rpx;

			>view {
				flex: 1;
			}
		}

		.title>view:nth-child(1) {
			font-weight: normal;
		}

		.title>view:nth-child(2) {
			position: relative;
			flex: 3 !important;
			color: $-color-muted;
			font-size: 22rpx;
			padding-left: 10rpx;

			/deep/.u-notice-bar {
				padding: 0 !important;

				.u-swiper {
					margin: 0;
				}
			}

			&::before {
				content: "";
				position: absolute;
				width: 1px;
				height: 10px;
				background-color: gray;
				top: 50%;
				transform: translateY(-50%);
				left: -5px;
				background-color: $-color-muted;
			}

		}

		.title>view:nth-child(3) {
			text-align: right;
			color: $-color-muted;
		}

		.row-fw .mu-grid {
			display: grid;
			grid-template-columns: repeat(2, 1fr);
			grid-gap: 20rpx;
			padding: 0 20rpx;

			>view {
				background-color: $-color-white;
				padding: 20rpx 15rpx;
				text-align: center;
				border-radius: 5rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;

				.item-left {
					display: flex;
					flex-direction: column;
					text-align: left;
				}

				.item-right {
					text-align: right;
				}
			}

			.mu-title {
				font-weight: normal;
			}

			.mu-text {
				font-size: 22rpx;
			}
		}


		.row-dt .matter {
			height: 150rpx;
			line-height: 150rpx;
			text-align: center;

			/deep/.u-divider {
				border-radius: 5rpx;
				background-color: #eeeeee !important;
			}
		}

		.row-hd {
			@extend .row-dt;
		}

		.row-zx {
			padding-bottom: 0;

			.column {
				display: flex;
				justify-content: space-between;

				&:nth-child(odd) {
					border-bottom: .1px solid #f0f0f0;
				}

				.column-left {
					margin-right: 20rpx;
					flex: 1.5;
					display: flex;
					flex-direction: column;
					justify-content: space-between;

					.pltitle {
						font-weight: 700;
					}

					.info {
						display: flex;
						justify-content: space-between;
						align-items: flex-end;
						font-size: 22rpx;
						line-height: 1.5;
						color: $-color-muted;
						//#ifdef H5
						line-height: 1.5;

						//#endif
						/deep/.u-avatar {
							vertical-align: sub;
						}

						//#ifdef H5
						>text /deep/span {
							vertical-align: sub;
						}

						//#endif


						.info-right {
							display: flex;
							align-items: center;

							.hit {
								position: relative;

								&::after {
									content: "";
									position: absolute;
									width: 1rpx;
									height: 10rpx;
									background-color: gray;
									top: 50%;
									transform: translateY(-50%);
									right: 35px;
									background-color: $-color-muted;
								}
							}
						}
					}
				}

				.column-right {
					flex: 1;
				}
			}
		}
	}

	.relevance {
		background-color: $-color-white;
		color: $-color-muted;
		padding: 10rpx 20rpx;

		.cell {
			display: flex;
			justify-content: space-between;
			align-items: center;

			>view {
				display: flex;
				align-items: center;
			}

			.tb {
				display: flex;
				flex-direction: column;
				justify-content: space-between;
			}
		}

	}
</style>